//排序
var order = 0;
var hash = window.location.hash.slice(1);
var cardId = hash.split(",")[0];
var groupId = hash.split(",")[1];
var topicId = hash.split(",")[2];
var orgId = hash.split(",")[3];
var isAdd = hash.split(",")[4];
var startUrl = "";
var flashMax = 200;//视频限制200m
var tools =[
            'bold', //加粗
            'italic', //斜体
            'fontfamily', 'fontsize','forecolor',
            'link', //引用
            'paragraph', //段落格式
            'justifyleft', //居左对齐
            'justifycenter', //居中对齐
            'justifyjustify', //两端对齐
            'insertorderedlist', //有序列表
            'insertunorderedlist' //无序列表
        ];
$(function() {
	//媒体服务id
	$("[name='mediaId']").val("894afc09-5248-11e6-8a08-3416d0d0a4c6");
	$("#addFile").mouseleave(function(){
		$("#addFileImg").hide();
	});
	$("#addText").mouseleave(function(){
		$("#addTextImg").hide();
	});
	$("#updateOrder").mouseleave(function(){
		$("#updateOrderImg").hide();
	});
	$("#addFile").mouseenter(function(){
		$("#addFileImg").show();
	});
	$("#addText").mouseenter(function(){
		$("#addTextImg").show();
	});
	$("#updateOrder").mouseenter(function(){
		$("#updateOrderImg").show();
	});
	//导航
	$.ajax({
		url:"../../../hivelearn/card/findCardNav.json",
		data:{id:cardId},
		success:function(data){
			$(".groupNav").text(data.data.groupNav);
			$(".groupNav").attr("title",data.data.groupNav);
			$(".topicNav").text(data.data.topicNav);
			$(".topicNav").attr("title",data.data.topicNav);
			$(".cardNav").text(data.data.cardNav);
			$(".cardNav").attr("title",data.data.cardNav);
		}
	});
	//卡片内容
	$.ajax({
		url:"../../../learn/card/findCardInfo.json",
		data:{id:cardId},
		success:function(data){
			var dom = _.template($('#editTextTpl').html());
			/*for(var i =0;i<data.data.cardTexts.length;i++){
				var d = data.data.cardTexts[i]
				if(d.attachList&&d.attachList.length>0){
					d.isDocument=1;
				}
			}*/
			//视频开头赋值
			startUrl = data.data.flashStartUrl;
			data.data.startUrl = startUrl;
			dom = dom(data.data);
			$("[name='cardTitle']").val(data.data.cardTitle);
			if(data.data.cardColor){
				$(".fmt-bg").css("background-color",data.data.cardColor);
				$("[name='cardColor']").val(data.data.cardColor);
			}
			if(data.data.cardColor){
				$(".ste-sctp-li").each(function(){
					$(this).find(".ste-sctp-yuan").each(function(){
						if(data.data.cardColor==$(this).css("background-color")){
							$(this).css("box-shadow","0 0 0 5px #ccc");
							return;
						}
					});
				});
			}
			if(data.data.cardCover){
				var img = "<img src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="
					+ data.data.cardCover+"\"/>";
				$(".fmt-bg").append(img);
				$("[name='cardCover']").val(data.data.cardCover);
			}
			$("#editText").html(dom);
			initSlide();
			
			for(var i = 0;i<data.data.cardTexts.length;i++){
				var d = data.data.cardTexts[i];
				if(d.content){
					createUEditor(d.cardTextId);
				}else if(d.playUrl){
					initFlash("my-video-"+d.cardTextId);
				}
			}
			/*$(".editinput").each(function(){
				$this = $(this);
				var id= $this.closest(".cardItem").find("[name='cardTextId']").val();
				$this.focus(function(){
					//$this.closest(".cardItem").find(".editinput").remove();
					$this.closest(".edit-textbox").find(".edit-delicon").hide();
				});
			})*/
		}
	});
	$("[data-toggle='tooltip']").tooltip();
	$(".uploadBtn").click(function() {
		$("#file").click();
	});
	$(".removeImg").click(function(){
		$(".fmt-bg").empty();
		$("[name='cardCover']").val("");
	});
	$(".ste-sctp-yuan").click(function(){
		$(".ste-sctp-li").each(function(){
			$(this).find(".ste-sctp-yuan").each(function(){
				$(this).css("box-shadow","0 0 0 #fff");
			});
		});
		$(this).css("box-shadow","0 0 0 5px #ccc");
		$(".fmt-bg").css("background-color",$(this).css("background-color"));
		$("#cardEditForm").find("[name='cardColor']").val($(this).css("background-color"));
	});
});
//添加文本
function addText(){
	$.ajax({
		url:"../../../hivelearn/cardtext/saveCardText.json",
		data:{"cardId":cardId,"groupId":groupId},
		success:function(data){
			if(data.success){
				var ele = "<div class='edit-textbox cardItem'>"
								+"<input type='hidden' name='cardTextId' value='"+data.data.cardTextId+"'/>"
								+"<textarea class='form-control editinput' id='"+data.data.cardTextId+"'></textarea>"
								+"<div class='edit-delicon' onclick='deleteSelf(this)'>"
									+"<span class='iconfont icon-delete'></span>"
								+"</div>"
							+"</div>";
				$(".edit-typebox").append(ele);
				createUEditor(data.data.cardTextId);
				/*$(".cardItem").each(function(){
					$this = $(this).find(".view");
					$this.focus(function(){
						$this.closest(".edit-textbox").find(".edit-delicon").hide();
					});
					$this.blur(function(){
						$this.closest(".edit-textbox").mouseleave(function(){
							$this.closest(".edit-textbox").find(".edit-delicon").hide();
						});
						$this.closest(".edit-textbox").mouseenter(function(){
							$this.closest(".edit-textbox").find(".edit-delicon").show();
						})
					});
				})*/
			}
		}
	})
}
function addImg(){
	$("#imgFile").click();
}
function addFile(){
	$("#addFileInput").click();
}
function addFlash(){
	$("#addFlash").click();
}
//排序
function updateOrder(){
	var card = new Object();
	card.cardId = cardId;
	//卡片内容组
	var cardTexts=[];
	$(".edit-typebox").find(".cardItem").each(function(e){
		var obj = new Object();
		obj.cardTextId = $(this).find("[name='cardTextId']").val();
		obj.orderNum = e;
		//cardTextId,内容,类型,排序
		if($(this).find("[name='attachId']")[0]){
			obj.attachId = $(this).find("[name='attachId']").val();
		}else if($(this).find(".editinput")[0]){
			var id = $(this).find(".editinput").attr("id");
			obj.content =UE.getEditor(id).getContent();
		}
		cardTexts.push(obj);
	});
	card.cardTexts = cardTexts;
	$.ajax({
		url : '../../../hivelearn/card/updateCard.json',
		data : {
			"cardInfo" : JSON.stringify(card),
			"groupId" : groupId,
			"forOrder":1
		},
		method:"post",
		dataType : "json",
		success : function(data) {
			$.ajax({
				url:"../../../learn/card/findCardInfo.json",
				data:{id:cardId},
				success:function(data){
					var dom = _.template($('#reorderTpl').html());
					for(var i = 0;i<data.data.cardTexts.length;i++){
						var d=data.data.cardTexts[i]
						if(d.content){
							d.content = $(d.content).text();
						}
					}
					dom = dom(data.data);
					$("#reorder").html(dom);
					Sortable.create($("#reorder")[0], {
						group : "omega"
					});
				}
			})
			$("#changeOrder").modal({backdrop: 'static', keyboard: true});
			console.log("save success");
		}
	})
}
//保存排序
function saveOrder(){
	var card = new Object();
	var objs = [];
	$("#reorder").find(".reorder-item").each(function(e){
		var obj = new Object();
		var id = $(this).attr("id");
		obj.cardTextId = id;
		obj.orderNum = e;
		objs.push(obj);
	});
	card.cardTexts = objs;
	if(objs.length>0){
		$.ajax({
			url:"../../../hivelearn/cardtext/updateCardTextOrder.json",
			data: {
				"cardInfo" : JSON.stringify(card),
				"groupId" : groupId
			},
			success:function(data){
				//刷新
				reloadCardText();
			}
		})
	}
}
//刷新内容
function reloadCardText(){
	//卡片内容
	$.ajax({
		url:"../../../learn/card/findCardInfo.json",
		data:{id:cardId},
		success:function(data){
			var dom = _.template($('#editTextTpl').html());
			/*for(var i =0;i<data.data.cardTexts.length;i++){
				var d = data.data.cardTexts[i]
				if(d.attachList&&d.attachList.length>0){
					d.isDocument=1;
				}
			}*/
			data.data.startUrl = startUrl;
			dom = dom(data.data);
			$("#editText").html(dom);
			initSlide();
			for(var i = 0;i<data.data.cardTexts.length;i++){
				var d = data.data.cardTexts[i];
				if(d.content){
					deleteUEditor(d.cardTextId);
					createUEditor(d.cardTextId);
				}else if(d.playUrl){
					videojs("my-video-"+d.cardTextId).dispose();
					
					initFlash("my-video-"+d.cardTextId);
				}
			}
			/*$(".cardItem").each(function(){
				$this = $(this).find(".view");
				$this.focus(function(){
					$this.closest(".edit-textbox").find(".edit-delicon").hide();
				});
				$this.blur(function(){
					$this.closest(".edit-textbox").mouseleave(function(){
						$this.closest(".edit-textbox").find(".edit-delicon").hide();
					});
					$this.closest(".edit-textbox").mouseenter(function(){
						$this.closest(".edit-textbox").find(".edit-delicon").show();
					})
				});
			})*/
		}
	});
}
function deleteSelf(e){
	$(e).closest(".cardItem").remove();
}
function updateCard(){
	var card = new Object();
	card.cardId = cardId;
	card.cardTitle = $("[name='cardTitle']").val();
	card.cardColor = $("[name='cardColor']").val();
	card.cardCover = $("[name='cardCover']").val();
	//卡片内容组
	var cardTexts=[];
	$(".edit-typebox").find(".cardItem").each(function(e){
		var obj = new Object();
		obj.cardTextId = $(this).find("[name='cardTextId']").val();
		obj.orderNum = e;
		//cardTextId,内容,类型,排序
		if($(this).find("[name='attachId']")[0]){
			obj.attachId = $(this).find("[name='attachId']").val();
		}else if($(this).find(".editinput")[0]){
			var id = $(this).find(".editinput").attr("id");
			obj.content =UE.getEditor(id).getContent();
		}
		cardTexts.push(obj);
	});
	card.cardTexts = cardTexts;
	$.ajax({
		url : '../../../hivelearn/card/updateCard.json',
		data : {
			"cardInfo" : JSON.stringify(card),
			"groupId" : groupId
		},
		method:"post",
		dataType : "json",
		success : function(data) {
			toList();
		}
	})
}
/***********图片上传*************/
/*function uploadImgFile(e) {
	if ($("#imgFile").val()&&checkfile(e)) {
		$.ajax({
			url : "../../../hivelearn/topic/uploadImage.json",
			data : new FormData($('#uploadImgForm')[0]),
			method : "post",
			processData : false,
			contentType : false,
			cache : false,
			success : function(data) // 服务器成功响应处理函数
			{
				var attachid = data.data.attachid;
				$.ajax({
					url:"../../../hivelearn/cardtext/saveCardText.json",
					data:{"cardId":cardId,"groupId":groupId},
					success:function(data){
						var img = "<div class=\"edit-imagebox cardItem\">"
							+"<input type='hidden' name='cardTextId' value='"+data.data.cardTextId+"'/>"
							+"<img class=\"edit-image\" src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="
						+ attachid+"\"/>"
							+"<div class=\"edit-delicon\" onclick=\"deleteSelf(this)\">"
							+"<span class=\"iconfont icon-delete\"></span>"
							+"</div>"
							+"<input type='hidden' name='attachId' value='"+attachid+"'/>"
						+"</div>";
						$(".edit-typebox").append(img);
					}
				});
				console.log("上传成功");
				$("#file").val("");
			},
			error : function(data)// 服务器响应失败处理函数
			{
				console.log("服务器异常");
				$("#file").val("");
			}
		});
	}

	return false;
}*/
function toList(item){
	if(isAdd&&item){
		$.ajax({
			url:"../../../hivelearn/card/deleteCardByIds.json",
			data:{"id":cardId,"groupId":groupId},
			success:function(data){
				window.location.href="../studyTalk/studyTalk.html#"+topicId+","+groupId+","+orgId;
			}
		})
	}else{
		window.location.href="../studyTalk/studyTalk.html#"+topicId+","+groupId+","+orgId+",2"+","+cardId;
	}
}
/***********封面图片上传*************/
function uploadFile(e) {
/*	if ($("#file").val()&&checkfile(e)) {
		$.ajax({
			url : "../../../hivelearn/topic/uploadImage.json",
			data : new FormData($('#uploadForm')[0]),
			method : "post",
			processData : false,
			contentType : false,
			cache : false,
			success : function(data) // 服务器成功响应处理函数
			{
				if($(".fmt-bg").find("img")[0]){
					$(".fmt-bg").find("img").attr("src","../../../components/gtattachment/open/downloadAttachment.json?attachmentId="
							+ data.data.attachid);
				}else{
					var img = "<img src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="
						+ data.data.attachid+"\"/>";
					$(".fmt-bg").append(img);
				}
				$("#cardEditForm").find('[name="cardCover"]').val(data.data.attachid);
				console.log("上传成功");
				$("#file").val("");
			},
			error : function(data)// 服务器响应失败处理函数
			{
				console.log("服务器异常");
				$("#file").val("");
			}
		});
	}

	return false;*/
	 $("#uploadForm").ajaxSubmit({
	    	url: "../../../hivelearn/topic/uploadImage.json?_t="+new Date().getTime(),
	        data:$("#uploadForm").serialize(),
	        dataType:"json",
	        success:function(data){
	        	if($(".fmt-bg").find("img")[0]){
					$(".fmt-bg").find("img").attr("src","../../../components/gtattachment/open/downloadAttachment.json?attachmentId="
							+ data.attachid);
				}else{
					var img = "<img src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="
						+ data.attachid+"\"/>";
					$(".fmt-bg").append(img);
				}
				$("#cardEditForm").find('[name="cardCover"]').val(data.attachid);
				console.log("上传成功");
				$("#file").val("");
			},
			error:function(data){
				console.log("服务器异常");
				$("#file").val("");
			}
	    });
}
//检查
/*function checkfile(target) {
	var isIE = /msie/i.test(navigator.userAgent) && !window.opera; 
	var fileSize = 0;
	var filetypes = [ ".jpg", ".png", ".gif"];
	var filepath = target.value;
	var filemaxsize = 1024 * 2;// 2M
	if (filepath) {
		var isnext = false;
		var fileend = filepath.substring(filepath.indexOf("."));
		if (filetypes && filetypes.length > 0) {
			for ( var i = 0; i < filetypes.length; i++) {
				if (filetypes[i] == fileend) {
					isnext = true;
					break;
				}
			}
		}
		if (!isnext) {
			$("#msgModal").find(".msg").text("请选择.png，.jpg，.gif图片文件上传");
			$("#msgModal").modal("show");
			target.value = "";
			return false;
		}
	} else {
		return false;
	}
	if (isIE && !target.files) {
		var filePath = target.value;
		var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
		if (!fileSystem.FileExists(filePath)) {
			$("#msgModal").find(".msg").text("图片不存在，请重新输入！");
			$("#msgModal").modal("show");
			return false;
		}
		var file = fileSystem.GetFile(filePath);
		fileSize = file.Size;
	} else {
		fileSize = target.files[0].size;
	}

	var size = fileSize / 1024;
	if (size > filemaxsize) {
		$("#msgModal").find(".msg").text("图片大小不能大于" + filemaxsize / 1024 + "M！");
		$("#msgModal").modal("show");
		target.value = "";
		return false;
	}
	if (size <= 0) {
		$("#msgModal").find(".msg").text("图片大小不能为0M！");
		$("#msgModal").modal("show");
		target.value = "";
		return false;
	}
	return true;
}*/
/***********图片上传*************/

/***********图片上传*************/
function uploadImgFile(e) {
	$("#uploadImgForm").ajaxSubmit({
    	url: "../../../hivelearn/topic/uploadImage.json?_t="+new Date().getTime(),
        data:$("#uploadImgForm").serialize(),
        dataType:"json",
        success:function(data){
        	var attachid = data.attachid;
			$.ajax({
				url:"../../../hivelearn/cardtext/saveCardText.json",
				data:{"cardId":cardId,"groupId":groupId},
				success:function(data){
					var img = "<div class=\"edit-imagebox cardItem\">"
						+"<input type='hidden' name='cardTextId' value='"+data.data.cardTextId+"'/>"
						+"<img class=\"edit-image\" src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="
					+ attachid+"\"/>"
						+"<div class=\"edit-delicon\" onclick=\"deleteSelf(this)\">"
						+"<span class=\"iconfont icon-delete\"></span>"
						+"</div>"
						+"<input type='hidden' name='attachId' value='"+attachid+"'/>"
					+"</div>";
					$(".edit-typebox").append(img);
				}
			});
			console.log("上传成功");
			$("#file").val("");
		},
		error:function(data){
			console.log("服务器异常");
			$("#file").val("");
		}
    });
	/*if ($("#imgFile").val()&&checkfile(e)) {
		$.ajax({
			url : "../../../hivelearn/topic/uploadImage.json",
			data : new FormData($('#uploadImgForm')[0]),
			method : "post",
			processData : false,
			contentType : false,
			cache : false,
			success : function(data) // 服务器成功响应处理函数
			{
				var attachid = data.data.attachid;
				$.ajax({
					url:"../../../hivelearn/cardtext/saveCardText.json",
					data:{"cardId":cardId,"groupId":groupId},
					success:function(data){
						var img = "<div class=\"edit-imagebox cardItem\">"
							+"<input type='hidden' name='cardTextId' value='"+data.data.cardTextId+"'/>"
							+"<img class=\"edit-image\" src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="
						+ attachid+"\"/>"
							+"<div class=\"edit-delicon\" onclick=\"deleteSelf(this)\">"
							+"<span class=\"iconfont icon-delete\"></span>"
							+"</div>"
							+"<input type='hidden' name='attachId' value='"+attachid+"'/>"
						+"</div>";
						$(".edit-typebox").append(img);
					}
				});
				console.log("上传成功");
				$("#file").val("");
			},
			error : function(data)// 服务器响应失败处理函数
			{
				console.log("服务器异常");
				$("#file").val("");
			}
		});
	}

	return false;*/
}
//function toList(){
//	window.location.href="../studyTalk/studyTalk.html#"+topicId+","+groupId+","+orgId;
//}
/***********文档上传*************/
function addUploadFile(e) {
	/*if ($("#addFileInput").val()&&checkAddfile(e)) {
		showloading();
		$.ajax({
			url : "../../../learn/card/uploadFile.json",
			data : new FormData($('#addFileForm')[0]),
			method : "post",
			processData : false,
			contentType : false,
			cache : false,
			success : function(data) // 服务器成功响应处理函数
			{
				var attachid = data.data.attach.attachid;
				var attachList = data.data.attachList;
				$.ajax({
					url:"../../../hivelearn/cardtext/saveCardText.json",
					data:{"cardId":cardId,"groupId":groupId},
					success:function(data){
						var ele = "<div class=\"edit-imagebox cardItem isDocument\">"
							+"<input type='hidden' name='cardTextId' value='"+data.data.cardTextId+"'/>"
							+"<div class=\"col-lg-12\" style=\"text-align:center;border: 1px solid #ccc;border-radius: 5px;\">"
							+"<div class=\"ck-slide\" style=\"margin:0 auto;overflow: hidden;\">"
								+"<ul class=\"ck-slide-wrapper\">";
						for(var i = 0;i<attachList.length;i++){
							if(i==0){
								ele += "<li>"
										+"<img style=\"cursor:default;\" src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="+attachList[i].attachid+"\">"
									+"</li>";	
							}
							ele += "<li style=\"display:none;\">"
										+"<img style=\"cursor:default;\" src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="+attachList[i].attachid+"\">"
									+"</li>";
						}
							ele+="</ul>"
								+"<a href=\"javascript:;\" class=\"ctrl-slide ck-prev\">上一张</a> <a href=\"javascript:;\" class=\"ctrl-slide ck-next\">下一张</a>"
								+"<div class=\"ck-slidebox\">"
									+"<div class=\"slideWrap\">"
										+"<span class=\"imgPage\" ></span>"
									+"</div>"
								+"</div>"
							+"</div>"
							+"</div>"
							+"<div class=\"edit-delicon\" onclick=\"deleteSelf(this)\">"
								+"<span class=\"iconfont icon-delete\"></span>"
							+"</div>"
							+"<input type='hidden' name='attachId' value='"+attachid+"'/>"
						+"</div>";
						$(".edit-typebox").append(ele);
						initSlide();
					}
				});
				console.log("上传成功："+attachid);
				hideloading();
				$("#addFileInput").val("");
			},
			error : function(data)// 服务器响应失败处理函数
			{	
				hideloading();
				console.log("服务器异常");
				$("#addFileInput").val("");
			}
		});
	}

	return false;*/
	showloading();
	$("#addFileForm").ajaxSubmit({
    	url: "../../../learn/card/uploadFile.json?_t="+new Date().getTime(),
        data:$("#addFileForm").serialize(),
        dataType:"json",
        success:function(data){
        	var attachid = data.attach.attachid;
			var attachList = data.attachList;
			var cls = 'ck-slide';
			var hcls='';
			if(data.attach.attachextname=="ppt"||data.attach.attachextname=="pptx"){
				cls = 'ck-slide ppt';
				hcls='h-ppt';
			}
			$.ajax({
				url:"../../../hivelearn/cardtext/saveCardText.json",
				data:{"cardId":cardId,"groupId":groupId},
				success:function(data){
					var ele = "<div class=\"edit-imagebox cardItem isDocument "+hcls+"\">"
						+"<input type='hidden' name='cardTextId' value='"+data.data.cardTextId+"'/>"
						+"<div class=\"col-lg-12\" style=\"text-align:center;border: 1px solid #ccc;border-radius: 5px;\">"
						+"<div class=\""+cls+"\" style=\"margin:0 auto;overflow: hidden;\">"
							+"<ul class=\"ck-slide-wrapper\">";
					for(var i = 0;i<attachList.length;i++){
						if(i==0){
							ele += "<li>"
									+"<img style=\"cursor:default;\" src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="+attachList[i].attachid+"\">"
								+"</li>";
							
						}else{
							ele += "<li style=\"display:none;\">"
								+"<img style=\"cursor:default;\" src=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="+attachList[i].attachid+"\">"
								+"</li>";
						}
					}
						ele+="</ul>"
							+"<a href=\"javascript:;\" class=\"ctrl-slide ck-prev\">上一张</a> <a href=\"javascript:;\" class=\"ctrl-slide ck-next\">下一张</a>"
							+"<div class=\"ck-slidebox\">"
								+"<div class=\"slideWrap\">"
									+"<span class=\"imgPage\" ></span>"
								+"</div>"
							+"</div>"
						+"</div>"
						+"</div>"
						+"<div class=\"edit-delicon\" onclick=\"deleteSelf(this)\">"
							+"<span class=\"iconfont icon-delete\"></span>"
						+"</div>"
						+"<input type='hidden' name='attachId' value='"+attachid+"'/>"
					+"</div>";
					$(".edit-typebox").append(ele);
					initSlide();
				}
			});
			console.log("上传成功："+attachid);
			hideloading();
			$("#addFileInput").val("");
		},
		error:function(data){
			hideloading();
			console.log("服务器异常");
			$("#addFileInput").val("");
		}
    });
}
//检查
/*function checkAddfile(target) {
	var isIE = /msie/i.test(navigator.userAgent) && !window.opera; 
	var fileSize = 0;
	var filetypes = [ ".doc", ".docx", ".pdf",".xls",".xlsx",".txt"];
	var filepath = target.value;
	var filemaxsize = 1024 * 10;// 10M
	if (filepath) {
		var isnext = false;
		var fileend = filepath.substring(filepath.indexOf("."));
		if (filetypes && filetypes.length > 0) {
			for ( var i = 0; i < filetypes.length; i++) {
				if (filetypes[i] == fileend) {
					isnext = true;
					break;
				}
			}
		}
		if (!isnext) {
			$("#msgModal").find(".msg").text("请选择.doc，.docx，.pdf，.xls，.xlsx，.txt文件上传");
			$("#msgModal").modal("show");
			target.value = "";
			return false;
		}
	} else {
		return false;
	}
	if (isIE && !target.files) {
		var filePath = target.value;
		var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
		if (!fileSystem.FileExists(filePath)) {
			$("#msgModal").find(".msg").text("文件不存在，请重新输入！");
			$("#msgModal").modal("show");
			return false;
		}
		var file = fileSystem.GetFile(filePath);
		fileSize = file.Size;
	} else {
		fileSize = target.files[0].size;
	}

	var size = fileSize / 1024;
	if (size > filemaxsize) {
		$("#msgModal").find(".msg").text("文件大小不能大于" + filemaxsize / 1024 + "M！");
		$("#msgModal").modal("show");
		target.value = "";
		return false;
	}
	if (size <= 0) {
		$("#msgModal").find(".msg").text("文件大小不能为0M！");
		$("#msgModal").modal("show");
		target.value = "";
		return false;
	}
	return true;
}*/
/***********文档上传*************/

/***********视频上传开始*************/
function addFlashFile() {
	$("[name='resourceId']").val("");
	/*if ($("#addFlash").val()&&checkFlashfile(e)) {
		showloading();
		$.ajax({
			url:"../../../hivelearn/cardtext/saveCardText.json",
			data:{"cardId":cardId,"groupId":groupId},
			success:function(data){
					$("[name='resourceId']").val(data.data.cardTextId);
					//上传视频
					$.ajax({
						url : "../../../learn/card/uploadResourceFile.json",
						data : new FormData($('#addFlashForm')[0]),
						method : "post",
						processData : false,
						contentType : false,
						cache : false,
						success : function(data) // 服务器成功响应处理函数
						{
							var successFlag = data.data.success;
				    		var hasNextFlag = data.data.hasNext;
				    		var uploadStepBean = data.data.callBackParaMap;
				    		var messageInfo = data.data.messageInfo;
				    		console.log(messageInfo);
				    		if(successFlag){
				    			if(hasNextFlag){	//继续请求
				    				doUploadStep(uploadStepBean);
				    			}else{
				    				hideloading();
				    				console.log("-----------hasNextFlag1 is false-------------");
				    			}
				    		}else{
				    			hideloading();
				    			console.log("-----------successFlag2 is false-------------");
				    		}
							$("#addFlash").val("");
						},
						error : function(data)// 服务器响应失败处理函数
						{	
							hideloading();
							console.log("服务器异常");
							$("#addFlash").val("");
						}
					});
				
			}
		});
	}
	return false;*/
	showloading();
	$.ajax({
		url:"../../../hivelearn/cardtext/saveCardText.json",
		data:{"cardId":cardId,"groupId":groupId},
		success:function(data){
			$("[name='resourceId']").val(data.data.cardTextId);
			$("#addFlashForm").ajaxSubmit({
		    	url: "../../../learn/card/uploadResourceFile.json?_t="+new Date().getTime(),
		        data:$("#addFlashForm").serialize(),
		        dataType:"json",
		        success:function(data){
		        	var successFlag = data.success;
		    		var hasNextFlag = data.hasNext;
		    		var uploadStepBean = data.callBackParaMap;
		    		var messageInfo = data.messageInfo;
		    		console.log(messageInfo);
		    		if(successFlag){
		    			if(hasNextFlag){	//继续请求
		    				doUploadStep(uploadStepBean);
		    			}else{
		    				hideloading();
		    				console.log("-----------hasNextFlag1 is false-------------");
		    			}
		    		}else{
		    			hideloading();
		    			console.log("-----------successFlag2 is false-------------");
		    		}
					$("#addFlash").val("");
				},
				error:function(data){
					hideloading();
					console.log("服务器异常");
					$("#addFlash").val("");
				}
		    });
		}
	});
	
}
function doUploadStep(uploadStepBean){
	var url = "../../../learn/card/uploadFileStep.json";
	$.ajax({
		method : "post",
		url : url,
		data : uploadStepBean,
		success:function(data){
			var successFlag = data.data.success;
			var hasNextFlag = data.data.hasNext;
			var uploadStepBean = data.data.callBackParaMap;
			var messageInfo = data.data.messageInfo;
			console.log(messageInfo);
			if(successFlag){
				if(hasNextFlag){	//继续请求
					doUploadStep(uploadStepBean);
				}else{
					var id = $("[name='resourceId']").val();
					//获取远程视频信息
					$.ajax({
						url:"../../../learn/card/findPlayUrl.json",
						data:{"id":id},
						success:function(data){
							var ele = "<div class=\"st-videobox cardItem\">"
											+"<input type='hidden' name='cardTextId' value='"+id+"'/>"
											+"<video id=\"my-video-"+id+"\" class=\"video-js vjs-default-skin vjs-big-play-centered\" controls preload=\"auto\" width=\"670\" height=\"502\" poster=\"../../../components/gtattachment/open/downloadAttachment.json?attachmentId="+data.data.flashImgId+"\" data-setup=\"{}\">"
											+"<source src=\""+startUrl+data.data.playUrl+"\" type=\"video/mp4\">" 
											+"</video>"
											+"<div class='edit-delicon' onclick='deleteSelf(this)'>"
											+"<span class='iconfont icon-delete'></span>"
											+"</div>"
											+"<input type='hidden' name='attachId' value='"+id+"_video"+"'/>"
										+"</div>";
							$(".edit-typebox").append(ele);
							initFlash("my-video-"+id);
						}
					});
					hideloading();
					console.log("--------------hasNextFlag3 is false---------------");
				}
			}else{
				hideloading();
	    		console.log("--------------successFlag4 is false---------------");
			}
		}
	});
}
//检查
function checkFlashfile(target) {
	var isIE = /msie/i.test(navigator.userAgent) && !window.opera; 
	var fileSize = 0;
	var filetypes = [ ".mp4"];
	var filepath = target.value;
	var filemaxsize = 1024 * flashMax;// 200M
	if (filepath) {
		var isnext = false;
		var fileend = filepath.substring(filepath.indexOf("."));
		if (filetypes && filetypes.length > 0) {
			for ( var i = 0; i < filetypes.length; i++) {
				if (filetypes[i] == fileend) {
					isnext = true;
					break;
				}
			}
		}
		if (!isnext) {
			$("#msgModal").find(".msg").text("请选择.mp4文件上传");
			$("#msgModal").modal("show");
			target.value = "";
			return false;
		}
	} else {
		return false;
	}
	if (isIE && !target.files) {
		var filePath = target.value;
		var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
		if (!fileSystem.FileExists(filePath)) {
			$("#msgModal").find(".msg").text("文件不存在，请重新输入！");
			$("#msgModal").modal("show");
			return false;
		}
		var file = fileSystem.GetFile(filePath);
		fileSize = file.Size;
	} else {
		fileSize = target.files[0].size;
	}

	var size = fileSize / 1024;
	if (size > filemaxsize) {
		$("#msgModal").find(".msg").text("文件大小不能大于" + filemaxsize / 1024 + "M！");
		$("#msgModal").modal("show");
		target.value = "";
		return false;
	}
	if (size <= 0) {
		$("#msgModal").find(".msg").text("文件大小不能为0M！");
		$("#msgModal").modal("show");
		target.value = "";
		return false;
	}
	return true;
}
/***********视频上传结束*************/

function createUEditor(uEditor){
	 UE.getEditor(uEditor,{
		 toolbars: [
		            tools
		        ],
		        initialFrameWidth : 640,
		        initialFrameHeight: 226,
		        autoHeightEnabled: false,
		        autoFloatEnabled: true
	 })/*.ready(function() {
	        ue.setHeight(300);
	       //设置编辑器的内容
	       // ue.setContent('hello');
	       // //获取html内容，返回: <p>hello</p>
	      // var html = ue.getContent();
	      // //获取纯文本内容，返回: hello
	      // var txt = ue.getContentTxt();
	  });*/
	/* $("#"+uEditor).find(".view").blur(function(){
			deleteUEditor(id);
			$this.closest(".edit-textbox").mouseleave(function(){
				$this.closest(".edit-textbox").find(".edit-delicon").hide();
			});
			$this.closest(".edit-textbox").mouseenter(function(){
				$this.closest(".edit-textbox").find(".edit-delicon").show();
			})
		});*/
}
function deleteUEditor(uEditor){
	 UE.getEditor(uEditor).destroy();
}

var word_w = "600px";
var word_h = "830px";
var ppt_w = "600px";
var ppt_h = "370px";
function initSlide(){
	 $(".ck-slide").each(function(){
		if(!$(this).hasClass("ppt")){
				$(this).css("width",word_w);
				$(this).find("img").css("width",word_w);
				$(this).ckSlide({
					dir: 'x'
				});
	           $(this).find(".ck-slide-dir").css("height",word_h);
	           $(this).find(".ck-slide-dir").css("width",word_w);
          }else{
	       	   $(this).css("width",ppt_w);
	       	   $(this).find("img").css("width",ppt_w);
	       	   $(this).ckSlide({
					dir: 'x'
				});
	           $(this).find(".ck-slide-dir").css("height",ppt_h);
	           $(this).find(".ck-slide-dir").css("width",ppt_w);
          }
		});
}
function initFlash(id){
	videojs(id)/*.ready(function() {
		var myPlayer = this;
		myPlayer.play();
	});*/
}